<template>
	<div class="card-page">
		<tool-bar nav="" :title="action_name + 'mobileCodeLog'">
			<el-button size="mini" @click="$router.push('/log/mobile-code-log/add')" v-if="action=='edit'">新建</el-button>
			<el-button size="mini" @click="save_click" type="primary"> 保存</el-button>
		</tool-bar>
		<el-row :gutter="12" type="flex">
			<el-col>
				<el-card shadow="always">
					<div slot="header">
						<span>基本信息</span>
					</div>
					<kv label="module">
						<selector v-model="info.module" enum="MobileCodeModuleEnum" chk="*"/>
					</kv>
					<kv label="mobile">
						<el-input v-model="info.mobile" />
					</kv>
					<kv label="templateCode">
						<el-input v-model="info.templateCode" />
					</kv>
					<kv label="param">
						<el-input v-model="info.param" />
					</kv>
					<kv label="bizId">
						<el-input v-model="info.bizId" />
					</kv>
					<kv label="result">
						<el-input v-model="info.result" />
					</kv>
					<kv label="errorMessage">
						<el-input v-model="info.errorMessage" />
					</kv>
					<kv label="sentAt">
						<el-date-picker v-model="info.sentAt" placeholder="选择日期时间"  type="datetime" />
					</kv>
					<kv label="arrivedAt">
						<el-date-picker v-model="info.arrivedAt" placeholder="选择日期时间"  type="datetime" />
					</kv>
				</el-card>
			</el-col>
			<el-col>
				<el-card shadow="always">
					<div slot="header">
						<span>扩展信息</span>
					</div>
				</el-card>
			</el-col>
		</el-row>
	</div>
</template>
<style scoped>
</style>
<script>
/**
 * Created by CodeGenerator  at 2022-02-22 15:33:17
 */
export default {
	components: {},
	data() {
		return {
			MobileCodeModuleEnum: jv.enum.MobileCodeModuleEnum.getData(),
			info: {
				result: {},
			}, //子对象需要声明。
		}
	},
	props: {
		id: {type: String, default: ""}
	},
	computed: {
		action() {
			return this.id ? "edit" : "add";
		},
		action_name() {
			return {add: "添加", edit: "修改"}[this.action]
		}
	},
	mounted() {
		this.loadData();
	},
	methods: {
		async loadData() {
			if (!this.id) return;
			var res = await this.$http.post("/log/mobile-code-log/detail/" + this.id)
			this.info = res.data.data;
		},
		async save_click() {
			//校验
			if (this.chk() == false) {
				return;
			}

			var res =await this.$http.post("/log/mobile-code-log/save", this.info)
			//[axios拦截器中已处理了异常]。
			jv.info(this.action_name + " 成功");
			if (this.action == "add") {
				var id = res.data.data
				// jv.setLastRowId("/log/mobile-code-log/list", "list", id);
				this.$router.push("/log/mobile-code-log/edit/" + id)
			} else if (this.action == "edit") {
				this.$router.push("/log/mobile-code-log/list")
			}
		}
	}
}
</script>
